package ycl.scheduled.controller.sys;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import ycl.scheduled.common.ApiResult;
import ycl.scheduled.common.base.controller.BaseController;
import ycl.scheduled.common.base.entity.BaseEntity;
import ycl.scheduled.common.models.base.T;
import ycl.scheduled.common.models.req.scheduled.ScheduledCreateReq;
import ycl.scheduled.common.models.res.scheduled.ScheduledRes;
import ycl.scheduled.entity.SysUserScheduled;
import ycl.scheduled.service.SysUserScheduledService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户日程安排 前端控制器
 * </p>
 *
 * @author ycl
 * @since 2022-01-20 00:04:45
 */
@RestController
@RequestMapping("/sys/user/scheduled")
@Api(tags = "日程")
public class SysUserScheduledController extends BaseController {

	@Resource
	private SysUserScheduledService userScheduledService;

	@Override
	public ApiResult<? extends BaseEntity> getById(HttpServletRequest request, Long id) {
		SysUserScheduled scheduled = userScheduledService.getById(id);
		return ApiResult.success(scheduled);
	}


	@GetMapping("getSchedules")
	@ApiOperation("获取用户日程, YESTERDAY, TODAY, TOMORROW")
	@ApiOperationSupport(order = 11)
	public ApiResult<ScheduledRes> getSchedules(HttpServletRequest request, String time) {
		ScheduledRes res = new ScheduledRes();
		return ApiResult.success(res);
	}

	@PostMapping("verify")
	@ApiOperation("日程校验")
	@ApiOperationSupport(order = 21)
	public ApiResult<Object> verify(HttpServletRequest request, @RequestBody ScheduledCreateReq req) {
		int i = userScheduledService.verify(request, req);
		if (i == 1)
			// x > 90
			return ApiResult.success();
		else if (i == 0)
			// 60 < x < 90
			return ApiResult.success("您当前日期已有日程，确认创建日程？");
		else
			// x < 60
			return ApiResult.fail("您当前日期一个小时内已有日程，请合理安排时间");
	}

	@PostMapping("create")
	@ApiOperation("创建日程, 先调用日程校验")
	@ApiOperationSupport(order = 22)
	public ApiResult<T> create(HttpServletRequest request, @RequestBody ScheduledCreateReq req) {
		userScheduledService.create(request, req);
		return ApiResult.success();
	}


}

